/*
 * @Author: your name
 * @Date: 2021-01-11 17:27:04
 * @LastEditTime: 2021-04-26 17:16:26
 */
import router from './router'
import store from './store'
// eslint-disable-next-line no-unused-vars
import { getToken, setToken, removeToken } from '@utils/auth'

const token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbkFjY291bnQiOiJmZjgwODA4MTczYzQ5NzcyMDE3M2M0OWQwNTkwMDAwMyIsInZhbGlkYXRpb25Db2RlIjoibWFuYWdlciIsImV4cCI6MTU5ODUwMDI1Mn0.iZTrWK36OFc7heOtLzPZ0yD7BC2YIGCBMBibnimsITw'
const userId = 'ff808081733c35e401733c3651af0000'
setToken(token, userId)

// removeToken()

router.beforeEach(async (to, from, next) => {
  const { token } = getToken()
  if (!store.getters.userInfo) await store.dispatch('getInfo')
  if (token) {
    next()
  } else {
    const whiteList = ['/shopOpen']
    whiteList.includes(to.path) ? next() : next('/shopOpen')
  }
})
